package com.xbongbong.sso.enums;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 授权参数支持的函数枚举
 */
@Getter
public enum OauthFunctionEnum {
    /**
     *
     */
    UUID("UUID()", "UUID()", "获取随机字符串，基于UUID.randomUUID()"),
    CONCATENATE("CONCATENATE()", "CONCATENATE()", "多个字符串连接"),
    SYSTIME("SYSTIME()","SYSTIME()", "获取服务器当前时间的时间戳(秒)"),
    BASE64("BASE64()","BASE64()", ""),
    SHA256("SHA256()","SHA256()", ""),
    MD5("MD5()","MD5()", ""),
    SYSTIMEMS("SYSTIMEMS()","SYSTIMEMS()", "获取服务器当前时间的时间戳(毫秒)"),
    UPPER("UPPER()","UPPER()", ""),
    LOWER("LOWER()","LOWER()", ""),
    UNKNOWN("未知","未知", ""),
    ;


    private String name;

    private String function;

    private String description;

    OauthFunctionEnum(String name, String function, String description) {
        this.name = name;
        this.function = function;
        this.description = description;
    }

    /**
     * 根据name获取枚举
     * @return
     */
    public static OauthFunctionEnum getByName(String name) {
        if (name == null) {
            return UNKNOWN;
        }
        for (OauthFunctionEnum cache : values()) {
            if (Objects.equals(cache.getName(), name)) {
                return cache;
            }
        }
        return UNKNOWN;
    }
    public static List<OauthFunctionEnum> getAll() {
        List<OauthFunctionEnum> list = new ArrayList<>();
        for (OauthFunctionEnum cache : values()) {
            if (Objects.equals(cache, UNKNOWN)) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }
}
